var app = getApp(),
  util = require("../../utils/util.js"),
  _location = ""; 
var base = require('./../../../config.js');

Page({
  data: {
    bomb: !1,
    showLoading: !0,
    imgUrls: [],
    docIndex: 0,
    url: wx.getStorageSync('url')
  },
  onSlideChangeEnd: function(e) {
    this.setData({
      docIndex: e.detail.current
    })
  },
  onLoad: function(o) {
    console.log(111111111);
    console.log(base);
    var n = this;
    console.log("zh_zbkq/pages/index/index?scene=".length);
    app.getUserInfo(function(e) {
      console.log(e), n.setData({
        userInfo: e
      });
      var t = decodeURIComponent(o.scene);
      if (null != t) var a = t;
      if (null != o.upper_partner) a = o.upper_partner;
      app.util.request({
        url: "entry/wxapp/MySx",
        data: {
          user_id: e.id
        },
        success: function(t) {
          console.log(t), 0 == t.data && "undefined" != a && app.util.request({
            url: "entry/wxapp/Binding",
            cachetime: "0",
            data: {
              fx_user: e.id,
              user_id: a
            },
            success: function(t) {
              console.log("这是成为下级分销商" + a), console.log(t);
            }
          });
        }
      });
    }), n.setData({
      rande: app.globalData.rande,
      start: app.util.time(),
      end: app.util.addDate(app.util.time(), 28)
    }), n.refresh();
  },
  date: function(t) {
    var e = wx.getStorageSync("day1"),
      a = wx.getStorageSync("day2"),
      o = wx.getStorageSync("day"),
      n = app.util.time();
    if ("" == e) {
      var i = app.util.time();
      wx.setStorageSync("datein", i);
    } else if (e < n) i = n;
    else i = e;
    if ("" == a) var l = app.util.addDate(n, 1);
    else {
      var s = app.util.addDate(n, 1);
      if (console.log(s), a < s) l = s;
      else l = a;
    }
    o = app.util.day(l, i);
    wx.setStorageSync("day1", i), wx.setStorageSync("day2", l), wx.setStorageSync("day", o),
      this.setData({
        datein: i,
        dateout: l,
        dateinDay: i.slice(5, 7),
        dateinMonth: i.slice(8, 10),
        dateoutDay: l.slice(5, 7),
        dateoutMonth: l.slice(8, 10),
        time: o,
        current_date: i,
        outWin: this.winDay(l),
        inWin: this.winDay(i)
      });
  },
  winDay: function (s) {
    console.log(s);
    var b = new Date(Date.parse(s.replace(/\-/g, "/")));
    var n = 0;
    switch (b.getDay()) {
      case 0:
        n = '日';
        break;
      case 1:
        n = '一';
        break;
      case 2:
        n = '二';
        break;
      case 3:
        n = '三';
        break;
      case 4:
        n = '四';
        break;
      case 5:
        n = '五';
        break;
      case 6:
        n = '六';
        break;
    }
    console.log(n);
    return n;
  },
  swiperUrl: function(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.id,
    })
  },
  refresh: function(t) {
    var a = this;
    app.util.request({
      url: "entry/wxapp/getad",
      cachetime: "0",
      data: {
        type: 4
      },
      success: function(t) {
        console.log(t);
        a.setData({
          imgUrls: t.data
        })
      }
    });
    app.util.request({
      url: "entry/wxapp/attachurl",
      cachetime: "0",
      success: function(t) {
        console.log(t), wx.setStorageSync("url", t.data), a.setData({
          url: t.data
        });
      }
    }), app.util.request({
      url: "entry/wxapp/GetNav",
      cachetime: "0",
      success: function(t) {
        if (console.log("首页导航"), console.log(t.data), 5 <= t.data.length) var e = t.data.splice(t.data.length - 5, 5);
        else e = t.data;
        a.setData({
          nav: e
        });
      }
    });
    app.util.request({
      url: "entry/wxapp/GetSystem",
      cachetime: "0",
      success: function(t) {
        console.log(t), wx.setStorageSync("platform", t.data), wx.setNavigationBarTitle({
          title: t.data.pt_name
        }), a.setData({
          platform: t.data,
          color: t.data.color
        }),
        wx.setNavigationBarColor({
          frontColor: '#000000',
          backgroundColor: '#ffffff'
        })
      }
    });
    app.util.request({
      url: "entry/wxapp/getad",
      cachetime: "0",
      data: {
        type: 1
      },
      success: function(t) {
        console.log(t);
        a.data.rande;
        0 < t.data.length && a.setData({
          getad: t.data,
          bomb: !0
        });
      }
    }), a.date();
  },
  guanbi: function(t) {
    this.setData({
      bomb: !1
    }), app.globalData.rande = 0;
  },
  search: function(t) {
    wx.navigateTo({
      url: "search",
      success: function(t) {},
      fail: function(t) {},
      complete: function(t) {}
    });
  },
  skip: function(t) {
    console.log(t);
    var e = t.currentTarget.dataset.src,
      a = t.currentTarget.dataset.appid,
      o = t.currentTarget.dataset.wb_src;
    if ("../register/register" == e && this.Membership(), "" != e && "../register/register" != e) {
      var n = e.replace(/[^0-9]/gi, "");
      e = e.replace(/(\d+|\s+)/g, "");
      console.log(e + n), console.log(n), wx.navigateTo({
        url: String(e) + String(n)
      });
    } else "" != a ? wx.navigateToMiniProgram({
      appId: a,
      success: function(t) {
        console.log(t);
      }
    }) : "" != o && wx.navigateTo({
      url: "link?link=" + o
    });
  },
  copyright: function(t) {
    var e = this.data.platform.tz_appid;
    wx.navigateToMiniProgram({
      appId: e,
      success: function(t) {
        console.log(t);
      }
    });
  },
  bindDateChange1: function(t) {
    console.log(t);
    var e = t.detail.value,
      a = this.data.dateout,
      o = (this.data.current_date, app.getTime2Time(a, e));
    wx.setStorageSync("day1", e), wx.setStorageSync("day2", a), wx.setStorageSync("day", o),
      console.log(t.detail.value);
    this.setData({
      datein: e,
      dateinDay: e.slice(5, 7),
      dateinMonth: e.slice(8, 10),
      time: o,
      inWin: this.winDay(e)
    });
  },
  bindDateChange2: function(t) {
    var that = this;
    var e = that.data.datein,
      a = t.detail.value,
      o = app.getTime2Time(a, e);
    wx.setStorageSync("day1", e), wx.setStorageSync("day2", a), wx.setStorageSync("day", o);
    console.log(t.detail.value);
    that.setData({
      dateout: a,
      dateoutDay: a.slice(5, 7),
      dateoutMonth: a.slice(8, 10),
      time: o,
      outWin: that.winDay(a),
    }),console.log(that.data.inWin);
  },
  wode: function(t) {
    wx.reLaunch({
      url: "../logs/logs"
    });
  },
  register: function(){
    wx.navigateTo({
      url: "../register/register"
    });
  },
  content: function(t) {
    var e = this.data.platform;
    console.log(e);
    2 == e.type ? wx.getLocation({
      type: "wgs84",
      success: function(t) {
        console.log(t);
        var e = t.latitude,
          a = t.longitude;
        _location = e + "," + a, wx.setStorageSync("latitude", t.latitude), wx.setStorageSync("longitude", t.longitude),
          wx.navigateTo({
            url: "../hotel_list/hotel_list?nearby=0"
          });
      },
      fail: function(t) {
        console.log(t), wx.hideLoading(), _location = 1, wx.showModal({
          title: "授权提示",
          content: "您取消了位置授权，小程序将无法正常使用，如需再次授权，请在我的-授权管理中进行授权，再次进入小程序即可",
          showCancel: !0,
          cancelText: "取消",
          cancelColor: "#333",
          confirmText: "确定",
          confirmColor: "#333",
          success: function(t) {},
          fail: function(t) {},
          complete: function(t) {}
        });
      }
    }) : wx.navigateTo({
        url: "../hotel_list/hotel_list?nearby=0"
    });
  },
  location: function(t) {
    wx.showLoading({
      title: "搜索附近酒店"
    }), wx.getLocation({
      type: "wgs84",
      success: function(t) {
        console.log(t);
        var e = t.latitude,
          a = t.longitude;
        _location = e + "," + a, wx.setStorageSync("latitude", t.latitude), wx.setStorageSync("longitude", t.longitude),
          wx.navigateTo({
            url: "../hotel_list/hotel_list?nearby=1"
          });
      },
      fail: function(t) {
        wx.hideLoading(), console.log(t), _location = 1, wx.showModal({
          title: "授权提示",
          content: "您取消了本次授权，小程序将无法正常使用，请点击确定或者在我的-授权管理中进行授权，再次重新进入小程序即可",
          showCancel: !0,
          cancelText: "取消",
          cancelColor: "#333",
          confirmText: "确定",
          confirmColor: "#333",
          success: function(t) {},
          fail: function(t) {},
          complete: function(t) {}
        });
      }
    });
  },
  getUserInfo: function(t) {
    app.globalData.userInfo = t.detail.userInfo, this.setData({
      userInfo: t.detail.userInfo,
      hasUserInfo: !0
    });
  },
  onShow: function() {
    var e = this;
    e.date(), app.getUserInfo(function(t) {
      console.log(t), e.setData({
        users: t
      });
    });
  },
  onPullDownRefresh: function() {
    this.refresh(), wx.stopPullDownRefresh();
  },
  Membership: function(t) {
    var e = this.data,
      a = e.users,
      o = e.platform.open_member;
    console.log(o), 1 == o && null != o ? (console.log("可以注册"), "" == a.zs_name || null == a.zs_name ? (console.log("检测到用户尚未注册会员"),
      wx.navigateTo({
        url: "../register/register"
      })) : (console.log("检测到用户已经注册会员"), wx.showModal({
      title: "温馨提示",
      content: "您已经注册了会员了哦"
    }))) : wx.showModal({
      title: "温馨提示",
      content: "平台未开放注册会员,请联系平台管理员"
    });
  },
  onReachBottom: function() {},
  onUnload: function() {},
  onShareAppMessage: function() {}
});